/**
 * (C) 2007 - 2009 Parleys.com NV.
 */
package com.parleys.core.service.impl;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.parleys.core.domain.Space;
import com.parleys.core.exception.SpaceNotFoundException;
import com.parleys.core.service.ChannelService;
import com.parleys.core.service.SpaceService;

/**
 * 
 * @author berkay
 *
 */
@Service
public class SpaceServiceImpl implements SpaceService
{

    @Autowired
    private ChannelService channelService;

    private Space space1 = new Space(1L, "JUGs Only", "This is the Space for JUGs", true);
    private Space space2 = new Space(2L, "Devoxx", "The Devoxx space", true);
    private Space space3 = new Space(3L, "Sandbox", "The Sandbox space", true);
    private Space space4 = new Space(4L, "Company", "The private company space", false);

    @PostConstruct
    public void populateSpaces()
    {
        // JUGs Only
        space1.addChannel(channelService.getChannel(1L));
        space1.addChannel(channelService.getChannel(2L));

        // Devoxx
        space2.addChannel(channelService.getChannel(3L));
        space2.addChannel(channelService.getChannel(4L));
        space2.addChannel(channelService.getChannel(5L));

        // Sandbox
        space3.addChannel(channelService.getChannel(6L));

        // Company
        space4.addChannel(channelService.getChannel(7L));
    }

    @Override
    public Collection<Space> getPublicSpaces()
    {
        Collection<Space> spaces = new ArrayList<Space>();
        spaces.add(space1);
        spaces.add(space2);
        spaces.add(space3);
        return spaces;
    }

    @Override
    public Space getSpace(Long id)
    {
        for(Space space : getSpaces())
        {
            if(space.getId().equals(id))
            {
                return space;
            }
        }
        throw new SpaceNotFoundException(id);
    }

    @Override
    public Collection<Space> getSpaces()
    {
        Collection<Space> spaces = new ArrayList<Space>();
        spaces.add(space1);
        spaces.add(space2);
        spaces.add(space3);
        spaces.add(space4);
        return spaces;
    }

}
